package com.hmall.search.web;

import com.alibaba.fastjson.JSON;
import com.hmall.client.ItemClient;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Item;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.PageResult;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author: ahcfl
 * @Date: 2021年07月29日 18:38
 * @Description:
 */
@RestController
@RequestMapping("/search")
public class ItemSearchController {

    @Autowired
    private ItemClient itemClient;

    @Autowired
    private ISearchService searchService;

    @PostMapping(value = "/list", name = "基本搜索功能")
    public PageResult list(@RequestBody RequestParams params) {
        return searchService.getList(params);
    }


    @PostMapping(value = "/filters", name = "过滤项聚合")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        return searchService.getFilters(params);
    }

    @GetMapping(value = "/suggestion", name = "搜索栏自动补全")
    public List<String> suggestion(@RequestParam("key") String key) {
        return searchService.getSuggestion(key);
    }


}
